package View;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.io.Serializable;

import javax.swing.*;

/** this class provide the GUI window for entering pattern and sale to create new sale*/
public class RunSaleView extends JFrame implements Serializable {
	
	private static final long serialVersionUID = 42L;
	/**required  fields and buttons */
	JButton BackBtn;
	JButton btnRunSale;
	public JTextField SaleIdFielD;
	public JTextField PatternIdField;
	
	/** default and only constructor */
	public RunSaleView() {
		setTitle("Run Sale Operation");
		getContentPane().setLayout(null);
		this.setSize(436, 365);
		this.setLocationRelativeTo(null); 
		
		JLabel SelectMarketingPatternLbl = new JLabel("Marketing Pattern ID");
		SelectMarketingPatternLbl.setBounds(21, 66, 181, 23);
		SelectMarketingPatternLbl.setFont(new Font("Tahoma", Font.BOLD, 14));;
		getContentPane().add(SelectMarketingPatternLbl);
		
		btnRunSale = new JButton("Run Sale");
		btnRunSale.setFont(new Font("Tahoma", Font.BOLD, 14));
		btnRunSale.setBounds(240, 202, 99, 24);
		getContentPane().add(btnRunSale);
		
		 BackBtn = new JButton("Back");
		BackBtn.setFont(new Font("Tahoma", Font.BOLD, 14));
		BackBtn.setBounds(77, 202, 99, 25);
		getContentPane().add(BackBtn);
		
		JLabel lblInsertNewSaleid = new JLabel("Insert New SaleID");
		lblInsertNewSaleid.setFont(new Font("Tahoma", Font.BOLD, 14));
		lblInsertNewSaleid.setBounds(21, 128, 155, 20);
		getContentPane().add(lblInsertNewSaleid);
		
		
		SaleIdFielD = new JTextField();
		SaleIdFielD.setBounds(238, 129, 131, 20);
		getContentPane().add(SaleIdFielD);
		SaleIdFielD.setColumns(10);
		
		PatternIdField = new JTextField();
		PatternIdField.setBounds(238, 69, 131, 20);
		getContentPane().add(PatternIdField);
		PatternIdField.setColumns(10);
	}
	
	/**
	 * add listeners to add and back buttons function
	 * @param actionListener
	 */
	public void addRunSaleListener(ActionListener actionListener){
		btnRunSale.addActionListener(actionListener);
		BackBtn.addActionListener(actionListener);
	}
	
	/**
	 * show and hide window functions
	 */
	public void showWindow(){
		setVisible(true);
	}
	public void hideWindow(){
		setVisible(false);
	}	
	
	/**
	 * 
	 * @return text for field SaleID
	 */
	public String getSaleID()
	{
		return SaleIdFielD.getText();
	}
	/**
	 * 
	 * @return text for field PatternID
	 */
	public String getPatternID()
	{
		return PatternIdField.getText();
	}
	
	/**
	 * Function which clear fields
	 */
	public void clearFields(){
		SaleIdFielD.setText("");					
		PatternIdField.setText("");
	}
	
	/**
	 * 
	 * @return button btnRunSale
	 */
	public JButton getRunSaleBtn()
	{
		return this.btnRunSale;
	}
	
	/**
	 * 
	 * @return button BackBtn
	 */
	public JButton getBackBtn()
	{
		return this.BackBtn;
	}
}